package setdemo;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class SetApiDemo {

    public static void main(String[] args) {

        Set set = new HashSet();

        set.add("grape");
        set.add("banana");
        set.add("apple");
        set.add("orange");
        set.add(null);
        set.add("watermelon");
        set.add("apple");
        System.out.println(set.size());
        System.out.println("--------遍历所有元素----------");

        Iterator it = set.iterator();
        while(it.hasNext()){
            System.out.println(it.next());
        }

        System.out.println("---------删除'orange'元素之后---------");

        set.remove("orange");
        it = set.iterator();
        while(it.hasNext()){
            System.out.println(it.next());
        }
        Object[] arr = set.toArray();
        System.out.println("----------遍历对象数组-----------");
        for(Object obj: arr){
            System.out.println(obj);
        }

        System.out.println(set.contains("apple"));

        System.out.println(set.containsAll(Arrays.asList(new String[]{"apple", "grape", "watermelon"})));

        set.clear();

        System.out.println(set.isEmpty());
    }
}
